home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 321 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.5 KB  |  215 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.kei.com!wang!news
  3. From: emild@cs.technion.ac.il (Kohn Emil Dan)
  4. Subject: Re: EMM386 Problem - main.c (0/1) 
  5. Organization: Technion, Israel Institute of Technology
  6. Date: Thu, 4 Jan 1996 12:00:16 GMT
  7. Message-ID: <Pine.SV4.3.91-heb-2.04.960104122025.16292B-100000@cs.technion.ac.il>
  8. Sender: news@wang.com
  9.  
  10.  
  11.  
  12. On Wed, 3 Jan 1996, Paul Anderson wrote:
  13.  
  14. > "Ian G. Crozier" <ian_g_crozier@cngp.cng.com> wrote:
  15. > >panderso@ebtech.net (Paul Anderson) wrote:
  16. > >>I'm writing a menu program, I don't have much of it done yet, but on
  17. > >>running the exec of what I have done I get EMM386 Exception error #12
  18. > >>or #06.  I use Watcom's compiler.  I've attached the source.
  19. > >>
  20. > >I'm not surprised that you're having problems with your program.
  21. > >You've posted NINE messages, none of which give any useful information
  22. > >about your code!!
  23. > Uh-ohhhh.......  Sorry, mail reader hickup...  Some of them where
  24. > supposed to have the source attached, but, I can't change the
  25. > encoding!!!  I can just import the source, and here goes:
  26. > /*
  27. >       A menu prog, I am bored, so, why not put in *MY* bid to take
  28. >       the place of MM?  Oooohhhh....  Let's see,
  29. >       We want lots of configurability.  Igor!  Bring the config
  30. > files!
  31. > */
  32. > #include <stdio.h>
  33. > #include <stdlib.h>
  34.  
  35.  #include <string.h> 
  36.              ^-------------if you want to follow my advice, then you'll
  37.                            have to include this, too
  38.  
  39. > #include "menu.h"
  40. > main(int argc, char *argv[])
  41. > {
  42. >       int i=1;
  43.               
  44. >       /* Engage command-line parser! */
  45. >       if (argc == 1) {
  46. >               printf("\a\nUuuuhhhhh... Yer supposed to tell me the
  47. > config file name.");
  48. >               exit(0);
  49. >               }
  50. >       /* Okey-dokey, got that down, let's plop up the for loop.*/
  51. >       while(0==0)  /* Index=2(i.e. second param, first is: menu.exe)
  52. > Up Mr. Index. */
  53. >       {
  54. >              /* printf("%s", argv[i]);*/
  55. >              /* Bug test... */
  56. >              /*i=i + 1;*/
  57. >              /* We only need the config file name, nothing else. */
  58. >              /* Remember, include config file var def in h file. */
  59. >              config=fopen(argv[i], "r" );
  60. >              if (config == NULL)
  61. >                       {
  62. >                       /* Uh-oh...  *BIG* problem... */
  63. >                       printf("\a\nError: Unable to open config file
  64. > %s!", argv[i]);
  65. >                       printf("\nRead docs for help.");
  66. >                       exit(1);
  67. >                       }
  68. >              /* Now, let us test the error. */
  69. >              i=loadcnf(config);
  70. >              exit(0); /* Exit prog...*/
  71. >       }
  72. >        /*Let's roast this sucker....*/
  73. > }
  74. > atexit()
  75. > {
  76. >       fclose(config);
  77. >       return 0;
  78. > }
  79. > /* Config file data loader. */
  80. > int loadcnf(FILE *in)
  81. > {
  82. >       char indata[40];
  83. >       int tmp;
  84. >       /* Struct defed in menu.h... */
  85. >       fscanf(in,"%s", &indata);
  86. >       if (indata=="ON")
  87.         ^-----------Here you are comparing the address of the 
  88.                 first element of indata to the address 
  89.                 of "O" in "ON". I don't think they will 
  90.                 ever be equal
  91.  
  92.                 You should use
  93.                 if (strcmp(indata,"ON")==0)
  94.                 instead of your if statement
  95. >               {
  96. >               tmp=1;
  97. >               }
  98. >               else
  99. >               {
  100. >               tmp=0;
  101. >               }
  102. >       /*Parms.Color = tmp;*/
  103. >       /*indata="";*/
  104. >       fscanf(in, "%s", &indata);
  105.                          ^------Don't use the & here: indata as a 
  106.                 parameter to fscanf is a pointer to its 
  107.                 first  element (a char*, exactly what you need
  108.                 This applies to all your usages of fscanf
  109.                            ^----Data is read in indata
  110. >       Parms.EntryOne = indata; /* The beginnings of a long and
  111.                      painful process...*/
  112.                          ^-----EntryOne points to the first character of 
  113.                                         indata
  114. >       /*indata="";*/
  115. >       fscanf(in, "%s", &indata);
  116.                          ^-----new data is read into indata
  117.                                Now Params.EntryOne will point to the new 
  118.                 value that is stored in indata
  119. >       Parms.EntryOnePath = indata;
  120.             ^------Params.EntryOnePath points to the same 
  121.                 place, wherer Params.EntryOne Points 
  122. .
  123. .
  124. .
  125.  
  126.  
  127. After your assignments, all the Params fields will point to the same place:
  128. the last value read by fscanf in indata. I don't think this is what you 
  129. wanted.
  130.  
  131.  
  132. In order to corrrect the problem, replace the assignmnents like this:
  133.  
  134. Instead of
  135. Params.EntryOne=indata;
  136.  
  137. use:
  138.  
  139. if((Params.EntryOne=malloc(strlen(indata)+1))==NULL)
  140.     {
  141.         fprintf(stderr,"Not enough memory\n");
  142.     exit(1);
  143.     }
  144. strcpy(Parrams.EntryOne,indata);
  145.  
  146.  
  147.  
  148. OR
  149.  
  150. redeclare  the fields in the Parms struct to be char[40] instead of 
  151. char*, and  instead of
  152.  
  153. Params.EntryOne=indata;
  154.  
  155. use
  156.  
  157. strcpy(Params.Entryone,indata);
  158.  
  159.  
  160.  
  161.  
  162. >       /* YESSSSSSS!!!!!  I am *DONE* setting up the config
  163. > reader!!!*/
  164. >       return 0;
  165. > }
  166. > And the header file:
  167. > /* Filling garbage...*/
  168. > FILE *config;
  169. > struct
  170. > {
  171. >       int *Color;
  172. >       char *EntryOne;
  173. >       char *EntryOnePath;
  174. >       char *EntryTwo;
  175. >       char *EntryTwoPath;
  176. >       char *EntryThree;
  177. >       char *EntryThreePath;
  178. >       char *EntryFour;
  179. >       char *EntryFourPath;
  180. >       char *EntryFive;
  181. >       char *EntryFivePath;
  182. >       char *EntrySix;
  183. >       char *EntrySixPath;
  184. >       char *RegName;
  185. > } Parms;
  186. > int loadcnf(FILE *in);
  187. > /*Parms data;*/
  188. > Sorry for the mistake!!!  TTYL!
  189.  
  190. Hope that this helps.
  191.  
  192.  
  193.                     Best regards,
  194.  
  195.                                     Emil
  196.